<!DOCTYPE html>
<html lang="zh"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" type="image/x-icon" href="">
<title>代码生成</title>
<script type="text/javascript">
	function isIE() {
		return (!!window.ActiveXObject || 'ActiveXObject' in window);
	}
	function img404(event) {
		// 获取img对象，火狐是event.target ，IE及谷歌其他是event.srcElement
		var img = event.srcElement || event.target;
		img.onerror = null;
	}
	if (isIE()) {
		// console.log('I use IE.');
		var ua = navigator.userAgent;
		var isIE11 = -1 < ua.indexOf('Trident') && -1 < ua.indexOf("rv:11.0");
		if (isIE11) {
			document
					.write("<script type='text/javascript' src='http://www.foreworld.net/js/jquery/2.0.2/jquery.min.js?v2.0.2'><\/script>");
		}
	} else {
		document
				.write("<script type='text/javascript' src='http://www.foreworld.net/js/jquery/2.0.2/jquery.min.js?v2.0.2'><\/script>");
	}
</script><script type="text/javascript" src="http://www.foreworld.net/js/jquery/2.0.2//jquery.min.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if gte IE 9]>
	<script type='text/javascript' src='http://www.foreworld.net/js/jquery/2.0.2/jquery.min.js'></script>
<![endif]-->
<!--[if lt IE 9]>
	<script type='text/javascript' src='http://www.foreworld.net/js/jquery/1.11.3/jquery.min.js'></script>
	<script type='text/javascript' src='http://www.foreworld.net/js/html5shiv/3.7.2/html5shiv.min.js'></script>
	<script type='text/javascript' src='http://www.foreworld.net/js/respond/1.4.2/respond.min.js'></script>
<![endif]-->

<!--basic styles-->
<link rel="stylesheet"
	href="https://www.foreworld.net/js/ace/1.1.2/assets/css/bootstrap.min.css" />
<link rel="stylesheet"
	href="https://www.foreworld.net/js/ace/1.1.2/assets/css/bootstrap-responsive.min.css" />
<link rel="stylesheet"
	href="https://www.foreworld.net/js/ace/1.1.2/assets/css/font-awesome.min.css" />

<!--[if IE 7]>
<link rel="stylesheet" href="http://www.foreworld.net/js/ace/1.1.2/assets/css/font-awesome-ie7.min.css" />
<![endif]-->

<!--page specific plugin styles-->

<!--fonts-->
<link rel="stylesheet"
	href="https://www.foreworld.net/js/ace/1.1.2/assets/css/google/style.css" />

<!--ace styles-->
<link rel="stylesheet"
	href="https://www.foreworld.net/js/ace/1.1.2/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="https://www.foreworld.net/js/ace/1.1.2/assets/css/ace-responsive.min.css" />
<link rel="stylesheet"
	href="https://www.foreworld.net/js/ace/1.1.2/assets/css/ace-skins.min.css" />

<!--[if lte IE 8]>
<link rel="stylesheet" href="http://www.foreworld.net/js/ace/1.1.2/assets/css/ace-ie.min.css" />
<![endif]-->
<style>
.main-content {
	margin-left: 0px;
}

.main-content .breadcrumb {
	margin-left: 12px;
}

.form-horizontal .control-label {
	width: 88px;
}

.form-horizontal .controls {
	margin-left: 98px;
}

#btn_search {
	border-radius: 0;
	width: 50px;
	height: 25px;
	line-height: 25px;
	font-size: 13px;
	cursor: pointer;
}

#frm input {
  color: #0000FF;
}

#frm select {
  color: #0000FF;
}
</style>

<script>
function _toLowerCase(str){
  return str.charAt(0).toLowerCase() + str.slice(1);
}

/**
 * sql
 * 
 * @param
 * @param
 * @return
 */
function _procDataTypeForSql(x, y, z){
  switch(x){
    case 'varchar': return 'varchar('+ y +')';
    case 'number': return 'int('+ y +')';
    case 'decimal': return 'decimal('+ y +', '+ z +')';
    case 'date': return 'datetime';
    case 'longtext': return 'longtext';
    default: return '未知';
  }
}

/**
 * java
 * 
 * @param
 * @param
 * @return
 */
function _procDataTypeForJava(x){
  switch(x){
    case 'varchar': return 'String';
    case 'varchar[]': return 'String[]';
    case 'number': return 'Integer';
    case 'decimal': return 'BigDecimal';
    case 'date': return 'Date';
    case 'longtext': return 'String';
    default: return '未知';
  }
}

/**
 * elk
 * 
 * @param
 * @param
 * @return
 */
function _procDataTypeForElk(x){
  switch(x){
    case 'varchar': return 'keyword';
    case 'number': return 'integer';
    case 'decimal': return 'scaled_float';
    case 'date': return 'date';
    case 'longtext': return 'text';
    default: return '未知';
  }
}
</script>

</head>

<body style="">
	<div class="main-container container-fluid">
		<div class="main-content">
			<div class="breadcrumbs" id="breadcrumbs">
				<ul class="breadcrumb">
					<li><i class="icon-home home-icon"></i> <a href="javascript:;">首页</a>
						<span class="divider"> <i class="icon-angle-right arrow-icon"></i>
					</span></li>
					<li class="active">实体管理</li>
				</ul>
				<!--.breadcrumb-->
			</div>

			<div class="page-content">
				<div class="page-header position-relative">
					<h1>
						实体管理 <small><i class="icon-double-angle-right"></i> 代码生成</small>
					</h1>
				</div>
				<!--/.page-header-->

				<div class="row-fluid">
					<div class="span12">
						<form class="form-horizontal">
							<div class="control-group">
								<label class="control-label">查询条件：</label>

								<div class="controls">
									<select id="frm_proj">
										<option value=""></option>
									</select>
									<!--  -->
									<select id="frm_proj_entity"></select>
									<!--  -->
									<span class="help-button" title='点击搜索' id='btn_search'>搜索</span>
								</div>
							</div>
						</form>
					</div>
				</div>
				<!-- search -->

				<div class="row-fluid">
					<div class="span12">
						<div class="row-fluid">
							<div class="alert alert-block alert-error">
								<button type="button" class="close" data-dismiss="alert">
									<i class="icon-remove"></i>
								</button>
								<strong> <i class="icon-info-sign"></i> 系统提示：
								</strong>
							</div>
						</div>
						<!-- tips -->

						<div class="row-fluid">
							<p>
								<a href="javascript:newLine();"
									class="btn btn-app btn-info btn-mini"> <i
									class="icon-save bigger-200"></i> 添加 <span
									class="label label-inverse arrowed-in" id='itemCount'>6+</span>
								</a>
								<!--  -->
								<a href="javascript:genJSON();"
									class="btn btn-app btn-pink btn-mini"> <i
									class="icon-gift bigger-200"></i> 生成 <span
									class="label label-inverse arrowed-in">6+</span>
								</a>
								<!--  -->
							</p>
						</div>
						<!-- buttons -->

            <!-- form -->
						<div class="row-fluid">
							<div class="span12">
								<table class="table table-striped table-bordered table-hover checkTab" id='table_1'>
									<thead>
										<tr>
											<th class="center">
												<label>
													<input type="checkbox" />
													<span class="lbl"></span>
												</label>
											</th>
<th>id</th>
<th>name</th>
<th>comment</th>
<th>notBlank</th>
<th>is_pk</th>
<th>is_uuid</th>
<th>is_transient</th>
<th>data_type</th>
<th>s_regexp</th>
<th>s_regexp_message</th>
<th>n_len_max</th>
<th>n_len_mini</th>
<th>rel_entity_id</th>
<th>rel_entity_alias</th>
<th>rel_entity_prop_id</th>
<th>sql_opt_1</th>
<th>sql_opt_2</th>
										</tr>
									</thead>
								</table>
								<!-- table -->
							</div>
						</div>

						<div class="row-fluid">
							<div class="tabbable">
								<ul class="nav nav-tabs" id="myTab">
									<li class="active"><a data-toggle="tab" href="#info">
											<i class="green icon-edit bigger-110"></i> 修改属性
									</a></li>
								</ul>

								<div class="tab-content">
									<div class="tab-pane in active">
<form id='frm' role='form' class="form-horizontal" onsubmit='return pushData()'>

  <div class="control-group">
    <label class="control-label" for="frm_id">id</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_id" name='id' placeholder="id" v-model="id" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_name">name</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_name" name='name' placeholder="name" v-model="name" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_comment">comment</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_comment" name='comment' placeholder="comment" v-model="comment" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_notBlank">notBlank</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_notBlank" name='notBlank' placeholder="notBlank" v-model="notBlank" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_is_pk">is_pk</label>

    <div class="controls">
      <select id='frm_is_pk' name="is_pk" v-model="is_pk">
        <option value='true'>true</option>
        <option value='false'>false</option>
      </select>
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_is_uuid">is_uuid</label>

    <div class="controls">
      <select id='frm_is_uuid' name="is_uuid" v-model="is_uuid">
        <option value='true'>true</option>
        <option value='false'>false</option>
      </select>
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_is_transient">is_transient</label>

    <div class="controls">
      <select id='frm_is_transient' name="is_transient" v-model="is_transient">
        <option value='true'>true</option>
        <option value='false'>false</option>
      </select>
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_data_type">data_type</label>

    <div class="controls">
      <select id='frm_data_type' name="data_type" v-model="data_type">
        <option value='varchar'>varchar</option>
        <option value='number'>number</option>
        <option value='decimal'>decimal</option>
        <option value='date'>date</option>
        <option value='longtext'>longtext</option>
      </select>
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_s_regexp">s_regexp</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_s_regexp" name='s_regexp' placeholder="s_regexp" v-model="s_regexp" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_s_regexp_message">s_regexp_message</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_s_regexp_message" name='s_regexp_message' placeholder="s_regexp_message" v-model="s_regexp_message" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_n_len_max">n_len_max</label>

    <div class="controls">
      <input type="number" class='input-large' id="frm_n_len_max" name='n_len_max' placeholder="n_len_max" v-model="n_len_max" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_n_len_mini">n_len_mini</label>

    <div class="controls">
      <input type="number" class='input-large' id="frm_n_len_mini" name='n_len_mini' placeholder="n_len_mini" v-model="n_len_mini" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_rel_entity_id">rel_entity_id</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_rel_entity_id" name='rel_entity_id' placeholder="rel_entity_id" v-model="rel_entity_id" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_rel_entity_alias">rel_entity_alias</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_rel_entity_alias" name='rel_entity_alias' placeholder="rel_entity_alias" v-model="rel_entity_alias" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_rel_entity_prop_id">rel_entity_prop_id</label>

    <div class="controls">
      <input type="text" class='input-large' id="frm_rel_entity_prop_id" name='rel_entity_prop_id' placeholder="rel_entity_prop_id" v-model="rel_entity_prop_id" />
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_sql_opt_1">sql_opt_1</label>

    <div class="controls">
      <select id='frm_sql_opt_1' name="sql_opt_1" v-model="sql_opt_1">
        <option value='AND'>AND</option>
        <option value='OR'>OR</option>
      </select>
    </div>
  </div>

  <div class="control-group">
    <label class="control-label" for="frm_sql_opt_2">sql_opt_2</label>

    <div class="controls">
      <select id='frm_sql_opt_2' name="sql_opt_2" v-model='sql_opt_2'>
        <option value='='>=</option>
        <option value='<'>&lt;</option>
        <option value='>'>&gt;</option>
        <option value='LIKE'>LIKE</option>
        <option value='NOT LIKE'>NOT LIKE</option>
      </select>
    </div>
  </div>

  <div class="form-actions">
    <button class="btn btn-info" type='submit'>
      <i class="icon-ok bigger-110"></i> 提交
    </button>
    &nbsp; &nbsp;
    <button class="btn" type="reset">
      <i class="icon-undo bigger-110"></i> 重置
    </button>
  </div>
</form>
									</div>
								</div>
							</div>
						</div>
						<!-- form -->
					</div>
				</div>
			</div>
		</div>
	</div>

<script type='text/javascript'
	src='https://www.foreworld.net/js/underscore/1.5.1/underscore.min.js'></script>
<script type='text/javascript'
	src="https://www.foreworld.net/js/ace/1.1.2/assets/js/bootstrap.min.js"></script>
<script type='text/javascript'
	src="https://www.foreworld.net/js/ace/1.1.2/assets/js/ace-elements.min.js"></script>
<script type='text/javascript'
	src="https://www.foreworld.net/js/ace/1.1.2/assets/js/ace.min.js"></script>

<script type="text/javascript"
  src="https://www.foreworld.net/js/doT/1.1.3/doT.min.js"></script>

<script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script>

</body></html>

<script src="./index.js?v63"></script>
<script src='./demo1/table.checkTab.js?v3'></script>

<script>
doT.templateSettings = {
  evaluate:         /\{\{([\s\S]+?(\}?)+)\}\}/g,
  interpolate:      /\{\{=([\s\S]+?)\}\}/g,
  encode:           /\{\{!([\s\S]+?)\}\}/g,
  use:              /\{\{#([\s\S]+?)\}\}/g,
  useParams:        /(^|[^\w$])def(?:\.|\[[\'\"])([\w$\.]+)(?:[\'\"]\])?\s*\:\s*([\w$\.]+|\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})/g,
  define:           /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
  defineParams:     /^\s*([\w$]+):([\s\S]+)/,
  conditional:      /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
  iterate:          /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
  varname:          "it",
  strip:            false,
  append:           true,
  selfcontained:    false,
  doNotSkipEncoded: false,
};

function runCode(code) {
  var _window = window.open('', '_blank', '');
  _window.document.open('text/html', 'replace');
  _window.opener = null;
  _window.document.write(code);
  _window.document.close();
}
</script>

<script src='https://www.foreworld.net/js/jquery/ext/ext.form.js'></script>

<script>
function pushData(){
  var _list = jQuery('.table tbody input[type=checkbox]:checked').map(function(){
    return jQuery(this);
  }).get();

  if(1 !== _list.length) return false;

  var _x = _list[0];
  var _data = $('#frm').serializeObjectForm();
  console.log(_data);

  var _id = _x.parent().parent().next();
  _id.text(_data.id);

  var _name = _id.next();
  _name.text(_data.name);

  var _comment = _name.next();
  _comment.text(_data.comment);

  var _notBlank = _comment.next();
  _notBlank.text(_data.notBlank);

  var _is_pk = _notBlank.next();
  _is_pk.text(_data.is_pk);

  var _is_uuid = _is_pk.next();
  _is_uuid.text(_data.is_uuid);

  var _is_transient = _is_uuid.next();
  _is_transient.text(_data.is_transient);

  var _data_type = _is_transient.next();
  _data_type.text(_data.data_type);

  var _s_regexp = _data_type.next();
  _s_regexp.text(_data.s_regexp);

  var _s_regexp_message = _s_regexp.next();
  _s_regexp_message.text(_data.s_regexp_message);

  var _n_len_max = _s_regexp_message.next();
  _n_len_max.text(_data.n_len_max);

  var _n_len_mini = _n_len_max.next();
  _n_len_mini.text(_data.n_len_mini);

  var _rel_entity_id = _n_len_mini.next();
  _rel_entity_id.text(_data.rel_entity_id);

  var _rel_entity_alias = _rel_entity_id.next();
  _rel_entity_alias.text(_data.rel_entity_alias);

  var _rel_entity_prop_id = _rel_entity_alias.next();
  _rel_entity_prop_id.text(_data.rel_entity_prop_id);

  var _sql_opt_1 = _rel_entity_prop_id.next();
  _sql_opt_1.text(_data.sql_opt_1);

  var _sql_opt_2 = _sql_opt_1.next();
  _sql_opt_2.text(_data.sql_opt_2);

  return false;
}

function newLine(){
  var _tpl = doT.template($('#_tr').text());
  var _tr = _tpl({
    id: new Date().getTime(),
  });

  $('#table_1 tbody').append($(_tr));

  $('table.checkTab td input:checkbox').unbind('click');
  $('table.checkTab td input:checkbox').on('click', bindForm);
}

function bindForm(){
  var _id = $(this).parent().parent().next();
  _app.frm.id = _id.text();

  var _name = _id.next();
  _app.frm.name = _name.text();

  var _comment = _name.next();
  _app.frm.comment = _comment.text();

  var _notBlank = _comment.next();
  _app.frm.notBlank = _notBlank.text();

  var _is_pk = _notBlank.next();
  _app.frm.is_pk = _is_pk.text();

  var _is_uuid = _is_pk.next();
  _app.frm.is_uuid = _is_uuid.text();

  var _is_transient = _is_uuid.next();
  _app.frm.is_transient = _is_transient.text();

  var _data_type = _is_transient.next();
  _app.frm.data_type = _data_type.text();

  var _s_regexp = _data_type.next();
  _app.frm.s_regexp = _s_regexp.text();

  var _s_regexp_message = _s_regexp.next();
  _app.frm.s_regexp_message = _s_regexp_message.text();

  var _n_len_max = _s_regexp_message.next();
  _app.frm.n_len_max = _n_len_max.text();

  var _n_len_mini = _n_len_max.next();
  _app.frm.n_len_mini = _n_len_mini.text();

  var _rel_entity_id = _n_len_mini.next();
  _app.frm.rel_entity_id = _rel_entity_id.text();

  var _rel_entity_alias = _rel_entity_id.next();
  _app.frm.rel_entity_alias = _rel_entity_alias.text();

  var _rel_entity_prop_id = _rel_entity_alias.next();
  _app.frm.rel_entity_prop_id = _rel_entity_prop_id.text();

  var _sql_opt_1 = _rel_entity_prop_id.next();
  _app.frm.sql_opt_1 = _sql_opt_1.text();

  var _sql_opt_2 = _sql_opt_1.next();
  _app.frm.sql_opt_2 = _sql_opt_2.text();
}

function genJSON(){
  var _props = {};

  $('#table_1 tbody').find('tr').each(function(){
    var _tds = $(this).children();

    _props[_tds.eq(1).text()] = {
      "id": _tds.eq(1).text(),
      "name": _tds.eq(2).text(),
      "comment": ('' === _tds.eq(3).text() ? null : _tds.eq(3).text()),
      "notBlank": ('' === _tds.eq(4).text() ? null : _tds.eq(4).text()),
      "is_pk": ('true' === _tds.eq(5).text()),
      "is_uuid": ('true' === _tds.eq(6).text()),
      "is_transient": ('true' === _tds.eq(7).text()),
      "data_type": _tds.eq(8).text(),
      "s_regexp": ('' === _tds.eq(9).text() ? null : _tds.eq(9).text()),
      "s_regexp_message": ('' === _tds.eq(10).text() ? null : _tds.eq(10).text()),
      "n_len_max": (_tds.eq(11).text() - 0),
      "n_len_mini": (_tds.eq(12).text() - 0),
      "rel_entity_id": ('' === _tds.eq(13).text() ? null : _tds.eq(13).text()),
      "rel_entity_alias": ('' === _tds.eq(14).text() ? null : _tds.eq(14).text()),
      "rel_entity_prop_id": ('' === _tds.eq(15).text() ? null : _tds.eq(15).text()),
      "sql_opt_1": _tds.eq(16).text(),
      "sql_opt_2": _tds.eq(17).text(),
    }
  });

  var _json = JSON.stringify(_props);
  console.log(_json);
  alert(_json);
}
</script>

<script>
var _app = {};

_app.frm = new Vue({
  el: '#frm',
  data: {
    'id': '',
    'name': '',
    'comment': '',
    'notBlank': null,
    'is_pk': false,
    'is_uuid': false,
    'is_transient': false,
    'data_type': 'varchar',
    's_regexp': null,
    's_regexp_message': null,
    'n_len_max': 0,
    'n_len_mini': 0,
    'rel_entity_id': null,
    'rel_entity_alias': null,
    'rel_entity_prop_id': null,
    'sql_opt_1': 'AND',
    'sql_opt_2': '=',
  },
});
</script>

<script id='_tbody' type='text/x-dot-template'>
<tbody>
  {{ for (var _n in it.entities[it.selected].props) { }}
  <tr>
    <td class='center'>
      <label>
        <input type='checkbox' value='{{= it.entities[it.selected].props[_n].id }}' />
        <span class='lbl'></span>
      </label>
    </td>
    <td>{{= it.entities[it.selected].props[_n].id }}</td>
    <td nowrap>{{= it.entities[it.selected].props[_n].name }}</td>
    <td>{{= it.entities[it.selected].props[_n].comment || '' }}</td>
    <td>{{= it.entities[it.selected].props[_n].notBlank || '' }}</td>
    <td>{{= it.entities[it.selected].props[_n].is_pk }}</td>
    <td>{{= it.entities[it.selected].props[_n].is_uuid }}</td>
    <td>{{= it.entities[it.selected].props[_n].is_transient }}</td>
    <td>{{= it.entities[it.selected].props[_n].data_type }}</td>
    <td>{{= it.entities[it.selected].props[_n].s_regexp || '' }}</td>
    <td>{{= it.entities[it.selected].props[_n].s_regexp_message || '' }}</td>
    <td>{{= it.entities[it.selected].props[_n].n_len_max }}</td>
    <td>{{= it.entities[it.selected].props[_n].n_len_mini }}</td>
    <td>{{= it.entities[it.selected].props[_n].rel_entity_id || '' }}</td>
    <td>{{= it.entities[it.selected].props[_n].rel_entity_alias || '' }}</td>
    <td>{{= it.entities[it.selected].props[_n].rel_entity_prop_id || '' }}</td>
    <td>{{= it.entities[it.selected].props[_n].sql_opt_1 }}</td>
    <td>{{= it.entities[it.selected].props[_n].sql_opt_2 }}</td>
  </tr>
  {{ } }}
</tbody>
</script>

<script id='_tr' type='text/x-dot-template'>
<tr>
  <td class='center'>
    <label>
      <input type='checkbox' value='{{= it.id }}' />
      <span class='lbl'></span>
    </label>
  </td>
  <td>{{= it.id }}</td>
  <td></td>
  <td></td>
  <td></td>
  <td>false</td>
  <td>false</td>
  <td>false</td>
  <td>varchar</td>
  <td></td>
  <td></td>
  <td>0</td>
  <td>0</td>
  <td></td>
  <td></td>
  <td></td>
  <td>AND</td>
  <td>=</td>
</tr>
</script>
